<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>watch option</title>
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <script type="text/javascript" src="../assets/js/vue.js"></script>
</head>
<body>
    <h1>watch option</h1>
    <hr>
    <div id="app">
        <p>今日温度：{{wendu}}°</p>
        <p>穿衣建议：{{chuanyi}}</p>
        <p><button @click="up">升高温度</button><button @click="down">降低温度</button></p>
    </div>
    <script type="text/javascript">
        var app=new Vue({
            el:'#app',
            data:{
                wendu:14,
                chuanyi:'夹克长裙'
            },
            methods:{
                up:function(){
                    this.wendu+=5
                },
                down:function(){
                    this.wendu-=5
                }
            },
            watch:{
                wendu:function(newVal,oldVal){
                    if(newVal>=26){
                        this.chuanyi="T恤短袖";
                    }else if(newVal<26&&newVal>0){
                        this.chuanyi="夹克长裙";
                    }else{
                        this.chuanyi="棉衣羽绒服"
                    }

                }
            }
        }) 
    </script>
</body>
</html>